package com.fudan.adse.domain.vo;

import com.fudan.adse.domain.cont.CheckStatus;
import com.fudan.adse.domain.po.TicketOrder;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author Jerry Zhang
 * create: 2022-11-24 21:02
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StatisticsVO {
    private BigDecimal amount;
    private int count;
    private Date startDate;
    private Date endDate;

    public void initData(List<TicketOrder> orders) {
        this.amount = new BigDecimal(0);
        this.count = 0;
        orders.forEach(order -> {
            if (!CheckStatus.REFUND.getStatus().equals(order.getCheckStatus())) {
                this.amount = this.amount.add(order.getCosts());
                this.count++;
                if (startDate == null || order.getUpdateTime().compareTo(startDate) < 0) {
                    startDate = order.getUpdateTime();
                }
                if (endDate == null || order.getUpdateTime().compareTo(endDate) > 0) {
                    endDate = order.getUpdateTime();
                }
            }
        });
    }
}
